package com.gp.controller.user.distributor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gp.common.result.JsonResult;
import com.gp.common.utils.CookieUtils;
import com.gp.controller.BaseController;
import com.gp.model.dto.DistributorInfo;
import com.gp.model.entity.BaseUser;
import com.gp.model.entity.DwdDistributionIncome;
import com.gp.service.IBaseUserrelationService;
import com.gp.service.IDistributorIncomeService;

/**
 * @author: 弓成龙
 * @date  : 2018年3月4日
 * @email : gcx909109@sina.cn
 * @description:  分销商的收入从dwd_distribution_income 表中取
 */
@RestController
@RequestMapping("/distributor")
public class DistributorController extends BaseController{
  @Autowired
  private IDistributorIncomeService incomeService;
  @Autowired
  private IBaseUserrelationService relationService;
  /**
   * 查看自己的收入
   * @param userId
   * @return
   */
  @RequestMapping("/Income/{userId}")
  public JsonResult listUserIncome(@NotNull @PathVariable String userId) {
    Map<String, Object> columnMap = new HashMap<String, Object>();
    columnMap.put("userId", userId);
    List<DwdDistributionIncome> map = incomeService.selectByMap(columnMap);
    return renderSuccess(map);
  }
  
  /**
   * 查看自己的下级
   * @return
   */
  @RequestMapping("/lowers")
  public JsonResult listLowers() {
    Long userId = ((BaseUser)CookieUtils.obtainCurrentUser(CookieUtils.getCurrentRequest())).getId();
    List<DistributorInfo> map = relationService.listLowers(userId);
    return renderSuccess("操作成功",map);
  }
}

